<template>
  <div class="product">
    <div class="thumbnail">
      <img :src="data.img" />
      <div class="btn">
        <a @click="see" class="btn-round">查看详情</a
        ><a @click="get" class="left btn-round">立即获取</a>
      </div>
    </div>
    <div class="product-desc">
      <div class="title">{{ data.title }}</div>
      <div class="titlebtm">
        <Avatar :src="data.avatar" size="30" />
        <span class="user">{{ data.author }}</span>
        <div class="product-cat">
          <Icon
            type="ios-bookmark-outline"
            size="18"
            style="margin-right: 5px"
          />{{ data.category }}
        </div>
      </div>
      <p class="desc">
        {{ data.desc }}
      </p>
    </div>
    <div class="product-purchase">
      <div class="price-love">
        <span class="tag">{{ data.free ? "免费" : "付费" }}</span>
        <p>
          <Icon type="md-heart-outline" size="16" color="#7347c1" />{{
            data.like
          }}
        </p>
      </div>
      <div class="sell">
        <Rate disabled allow-half :value="data.star" />
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
export default {
  name: "product",
  props: {
    data: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  methods: {
    see() {
      Cookies.set("currData", JSON.stringify(this.data));
      this.$router.push({
        name: this.data.route,
      });
    },
    get() {
      window.open("http://xpay.exrick.cn/pay?xboot");
    },
  },
  mounted() {},
};
</script>

<style lang="less">
.product {
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgb(108 111 115 / 10%);
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;

  .thumbnail {
    position: relative;
    height: 223px;

    img {
      border-radius: 4px 4px 0 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .btn {
      position: absolute;
      top: calc(50% + 40px);
      opacity: 0;
      transform: translateY(-50%);
      z-index: 5;
      width: 100%;
      text-align: center;
      transition: 0.3s ease;

      .btn-round {
        display: inline-block;
        color: #fff;
        border: 1px solid #fff;
        font-weight: 500;
        padding: 0 30px;
        background: transparent;
        line-height: 40px;
        border-radius: 100px;

        &:hover {
          color: #0674ec;
          transition: 0.3s ease;
          background: #fff;
        }
      }

      .left {
        margin-left: 6px;
      }
    }

    &::before {
      opacity: 0;
      position: absolute;
      content: "";
      transition: 0.3s ease;
      height: 100%;
      opacity: 0;
      z-index: 2;
      border-radius: 4px 4px 0 0;
      width: 100%;
      top: 0;
      background-image: linear-gradient(to left, #7347c1 0%, #0674ec 100%);
      background-color: #7347c1;
      background: #0674ec;
      background-image: linear-gradient(to right, #7347c1, #0674ec);
      left: 0;
    }
  }

  &:hover .btn {
    opacity: 1;
    top: 50%;
  }

  &:hover .thumbnail::before {
    opacity: 0.9;
  }

  .product-desc {
    height: 222px;
    overflow: hidden;
    padding: 30px 30px 0 30px;

    .title {
      margin-bottom: 15px;
      display: inline-block;
      cursor: pointer;
      font-size: 20px;
      font-weight: 500;
      transition: 0.3s ease;
      color: #000;

      &:hover {
        color: #0674ec;
      }
    }

    .titlebtm {
      display: flex;
      align-items: center;
      padding-bottom: 23px;
      font-size: 15px;

      .user {
        margin-left: 6px;
        color: #000;
      }

      .product-cat {
        cursor: pointer;
        margin-left: 16px;
        color: #7347c1;
        transition: 0.3s ease;

        &:hover {
          color: #0674ec;
        }
      }
    }

    .desc {
      font-size: 16px;
      line-height: 26px;
      color: #555;
      font-weight: 400;
    }
  }

  .product-purchase {
    margin-top: 10px;
    border-top: 1px solid #ececec;
    padding: 15px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .price-love {
      display: flex;
      align-items: center;

      .tag {
        background: rgba(6, 116, 236, 0.1);
        line-height: 32px;
        display: inline-block;
        padding: 0 15px;
        color: #0674ec;
        margin-right: 10px;
        font-size: 15px;
        font-weight: 500;
        border-radius: 100px;
      }
    }

    .sell {
      .ivu-rate-star {
        margin-right: 3px;
      }

      .ivu-rate-star-full:before,
      .ivu-rate-star-half .ivu-rate-star-content:before {
        color: #ffc000;
      }
    }
  }
}
</style>
